﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json.Linq;
using park.Common;
namespace park.ListSensor
{
    public partial class ListSensorMdf : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BD();
            }
        }

        private void BD()
        {

            if (Request.QueryString["ID"] != null)
            {
                #region 正式代码
                string strID = Request.QueryString["ID"];
                cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();
                string strJson = sl.GetSensorById(strID);
                #endregion

                #region 测试代码
                //string strJson = ""
                //    + "{"
                //    + "\"SensorInfo\":{"
                //    + "\"ID\":1,"
                //    + "\"Code\":\"设备编号\","
                //    + "\"MeteredCoding\":\"咪表编码\","
                //    + "\"ParkingNo\":\"MCODE001\","
                //    + "\"Model\":\"咪表名称\","
                //    + "\"InstallTime\":\"2012-07-22\","
                //    + "\"Description\":\"配件说明...\""
                //    + "}"
                //+"}";
                #endregion
                JObject obj = JObject.Parse(strJson);

                this.txtID.Value = obj["SensorInfo"]["ID"].ToString();
                this.txtCode.Value = obj["SensorInfo"]["Code"].ToString();
                this.txtMeteredCoding.Value = obj["SensorInfo"]["MeteredCoding"].ToString();
                this.txtParkingNo.Value = obj["SensorInfo"]["ParkingNo"].ToString();
                this.txtModel.Value = obj["SensorInfo"]["Model"].ToString();
                this.txtInstalltime.Value = obj["SensorInfo"]["InstallTime"].ToString();
                this.txtDescription.Value = obj["SensorInfo"]["Description"].ToString();
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string strID = this.txtID.Value;
            string strCode = this.txtCode.Value;
            string strMeteredCoding = this.txtMeteredCoding.Value;
            string strParkingNo = this.txtParkingNo.Value;
            string strModel = this.txtModel.Value;
            string strInstalltime = DateTime.Parse(this.txtInstalltime.Value).ToString("yyyy-MM-dd");
            string strDescription =this.txtDescription.Value;


            cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();
            bool flag = sl.UpdateSensor(strID, strCode, strMeteredCoding, strParkingNo, strModel, strInstalltime, strDescription);

            string msg = flag ? "数据保存成功！" : "数据保存失败，请重试...";

            Page.ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), "<script>alert('" + msg + "');</script>");
        }
    }
}